package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjSpareParamFieldValOption;
import com.zb.mapper.ZjSpareParamFieldValOptionMapper;
import com.zb.service.ZjSpareParamFieldValOptionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 备件参数字段值关联选项值表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-12-30
 */
@Service
public class ZjSpareParamFieldValOptionServiceImpl extends ServiceImpl<ZjSpareParamFieldValOptionMapper, ZjSpareParamFieldValOption> implements ZjSpareParamFieldValOptionService {

    // 根据[备件参数字段值关联表ID]查询
    @Override
    public List<ZjSpareParamFieldValOption> getbySpareParamFieldValIds(List<Long> spareParamFieldValIds) {
        if (CollectionUtil.isEmpty(spareParamFieldValIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjSpareParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.select("id", "spare_relation_param_id", "spare_param_field_val_id", "opt_value");
        wrapper.in("spare_param_field_val_id", spareParamFieldValIds);
        return this.list(wrapper);
    }

    // 根据[备件参数关联表ID]删除选项值
    @Override
    public void deleteBySpareRelationParamId(Long spareRelationParamId) {
        QueryWrapper<ZjSpareParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.eq("spare_relation_param_id", spareRelationParamId);
        this.remove(wrapper);
    }

    // 根据[备件参数关联表ID]批量删除选项值
    @Override
    public void deleteBySpareRelationParamIds(List<Long> spareRelationParamIds) {
        if (CollectionUtil.isEmpty(spareRelationParamIds)) {
            return;
        }
        QueryWrapper<ZjSpareParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.in("spare_relation_param_id", spareRelationParamIds);
        this.remove(wrapper);
    }
}
